package main

import (
	"fmt"
)

func main() {
	sortedInt := []int{1, 45, 56, 71, 81, 96, 103, 210, 250}
	findInt := 0
	fmt.Println("please input the number you want")
	fmt.Scanln(&findInt)
	binaryFindInt(&sortedInt, 0, len(sortedInt)-1, findInt)
}

func binaryFindInt(sortedInt *[]int, leftIndex, rightIndex, findInt int) {
	if leftIndex > rightIndex {
		fmt.Println("cannot find it")
		return
	}
	// panic("unimplemented")
	middleIndex := (leftIndex + rightIndex) / 2
	if (*sortedInt)[middleIndex] > findInt {
		binaryFindInt(sortedInt, leftIndex, middleIndex-1, findInt)
	} else if (*sortedInt)[middleIndex] < findInt {
		binaryFindInt(sortedInt, middleIndex+1, rightIndex, findInt)
	} else {
		fmt.Printf("find it index = %d\n", middleIndex)

	}

}
